<script setup lang="ts">
import {getTeacherExamArrange} from "/@/api/hbmy_wx/examArrange";
import {Toast} from "vant";

onMounted(async () => {
  const res = await getTeacherExamArrange()
  const error = res.response.value.extend.error
  if (error === '暂无监考任务'){
    Toast('暂无监考任务')
    return
  }else {
    roomList.value = JSON.parse(res.response.value.extend.rooms)
    console.log(roomList.value);
    roomList.value = roomList.value.map(item => {
      // 使用正则表达式匹配日期和时间
      const regex = /(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2})--(\d{2}:\d{2})/;
      const match = item.testTime.match(regex);

      if (match) {
        // 更新对象的属性
        item.startDate = match[1];
        item.startTime = match[2];
        item.endTime = match[3];
      }
      return item;
    });
  }
})

const msg = ref()
const activeName = ref([])
const roomList = ref([])
const regex = /(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2})--(\d{2}:\d{2})/;
</script>

<template>
  <Header title="监考任务"></Header>
  <van-collapse v-model="activeName" ref="collapseRef">
    <van-collapse-item
        style="margin-top:10px; padding:0 10px; border-radius: 10px;"
        v-for="room in roomList"
        :name="room.num"
        :is-link="false"
        :readonly="true"
        size="large">
      <template #title>
        <span style="height:100%;line-height: 3vh; border-left: 5px solid #1989fa; margin-right: 5px"></span>
        {{room.courseName}}
      </template>
      <template #label>
        <p style="margin-top: 10px">{{ room.startDate }} {{ room.startTime }}-{{ room.endTime }}</p>
      </template>
      <template #value>
        <div style="margin-top: 13px">
          {{room.roomName}}
        </div>
      </template>
    </van-collapse-item>
  </van-collapse>
  <van-empty v-if="roomList.length === 0" image="search" description="无监考任务"/>

</template>

<style scoped lang="less">

</style>
